<template>
  <div>
    <el-input style="width: 70px" v-model="name"></el-input><el-button icon="el-icon-search" circle @click="paging(1)"></el-button><el-button plain @click="toAdd">增加</el-button>
    <el-table :data="page.list">

      <el-table-column prop="g_id" label="序号" width="340"></el-table-column>
      <el-table-column prop="g_name" label="类别" width="320"></el-table-column>

      <el-table-column label="操作" prop="g_id">

        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle @click="toUpdate(scope.row.g_id)"></el-button>
          <el-button type="danger" icon="el-icon-delete" circle @click="del(scope.row.g_id)"></el-button>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.curPage"
      :page-sizes="[2,3,4,5]"
      :page-size="page.pageSize"
      layout="total,sizes,prev,pager,next,jumper"
      :total="page.count">

    </el-pagination>
  </div>
</template>

<script>

  export default {
    data() {
      return {
        pageSize:2,
        page:{},
        name:'',
      }
    },
    methods:{
      paging(curPage){
        this.$axios.get('/GoodsServlet/listGoods?curPage='+curPage + '&g_name=' + this.name + '&pageSize=' + this.pageSize)
          .then(resp=>{
            this.page = resp.data;
          })
      },
      toUpdate(id){
        this.$router.push('/goods/update/' + id)
      },
      del(id){

        this.$axios.get('GoodsServlet/delGoods?g_id='+ id)
          .then(resp=>{
            this.paging(1)
          })
      },
      toAdd(){
        this.$router.push('/goods/add')
      },
      handleCurrentChange(newPage){
        this.paging(newPage)
      },
      handleSizeChange(newSize){
        this.pageSize = newSize;
        this.paging(1)
      }
    },
    created() {
      this.paging(1)
    },

  };
</script>

<style scoped>

</style>
